home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / gdb.new / gdb-3.98 / gdb / gdb.info-2 < prev    next >
Encoding:
Text File  |  1991-08-01  |  49.2 KB  |  1,252 lines

  1. Info file gdb.info, produced by Makeinfo, -*- Text -*- from input
  2. file gdb-all.texinfo.
  3.  
  4.    This file documents the GNU debugger GDB.
  5.  
  6.    Copyright (C) 1988, 1989, 1990, 1991 Free Software Foundation, Inc.
  7.  
  8.    Permission is granted to make and distribute verbatim copies of
  9. this
  10. manual provided the copyright notice and this permission notice are
  11. preserved on all copies.
  12.  
  13.    Permission is granted to copy and distribute modified versions of
  14. this
  15. manual under the conditions for verbatim copying, provided also that
  16. the section entitled "GNU General Public License" is included
  17. exactly as in the original, and provided that the entire resulting
  18. derived work is distributed under the terms of a permission notice
  19. identical to this one.
  20.  
  21.    Permission is granted to copy and distribute translations of this
  22. manual into another language, under the above conditions for
  23. modified versions, except that the section entitled "GNU General
  24. Public License" may be included in a translation approved by the
  25. Free Software Foundation instead of in the original English.
  26.  
  27. 
  28. File: gdb.info,  Node: Set Breaks,  Next: Set Watchpoints,  Prev: Breakpoints,  Up: Breakpoints
  29.  
  30. Setting Breakpoints
  31. -------------------
  32.  
  33.    Breakpoints are set with the `break' command (abbreviated `b').
  34.  
  35.    You have several ways to say where the breakpoint should go.
  36.  
  37. `break FUNCTION'
  38.      Set a breakpoint at entry to function FUNCTION.  When using
  39.      source languages that permit overloading of symbols, such as
  40.      C++, FUNCTION may refer to more than one possible place to break.
  41.      *Note Breakpoint Menus::, for a discussion of that situation.
  42.  
  43. `break +OFFSET'
  44. `break -OFFSET'
  45.      Set a breakpoint some number of lines forward or back from the
  46.      position at which execution stopped in the currently selected
  47.      frame.
  48.  
  49. `break LINENUM'
  50.      Set a breakpoint at line LINENUM in the current source file. 
  51.      That file is the last file whose source text was printed.  This
  52.      breakpoint will stop the program just before it executes any of
  53.      the code on that line.
  54.  
  55. `break FILENAME:LINENUM'
  56.      Set a breakpoint at line LINENUM in source file FILENAME.
  57.  
  58. `break FILENAME:FUNCTION'
  59.      Set a breakpoint at entry to function FUNCTION found in file
  60.      FILENAME.  Specifying a file name as well as a function name is
  61.      superfluous except when multiple files contain similarly named
  62.      functions.
  63.  
  64. `break *ADDRESS'
  65.      Set a breakpoint at address ADDRESS.  You can use this to set
  66.      breakpoints in parts of the program which do not have debugging
  67.      information or source files.
  68.  
  69. `break'
  70.      When called without any arguments, `break' sets a breakpoint at
  71.      the next instruction to be executed in the selected stack frame
  72.      (*note Stack::.).  In any selected frame but the innermost,
  73.      this will cause the program to stop as soon as control returns
  74.      to that frame.  This is similar to the effect of a `finish'
  75.      command in the frame inside the selected frame--except that
  76.      `finish' doesn't leave an active breakpoint.  If you use
  77.      `break' without an argument in the innermost frame, GDB will
  78.      stop the next time it reaches the current location; this may be
  79.      useful inside loops.
  80.  
  81.      GDB normally ignores breakpoints when it resumes execution,
  82.      until at least one instruction has been executed.  If it did
  83.      not do this, you would be unable to proceed past a breakpoint
  84.      without first disabling the breakpoint.  This rule applies
  85.      whether or not the breakpoint already existed when the program
  86.      stopped.
  87.  
  88. `break ... if COND'
  89.      Set a breakpoint with condition COND; evaluate the expression
  90.      COND each time the breakpoint is reached, and stop only if the
  91.      value is nonzero--that is, if COND evaluates as true.  `...'
  92.      stands for one of the possible arguments described above (or no
  93.      argument) specifying where to break.  *Note Conditions::, for
  94.      more information on breakpoint conditions.
  95.  
  96. `tbreak ARGS'
  97.      Set a breakpoint enabled only for one stop.  ARGS are the same
  98.      as for the `break' command, and the breakpoint is set in the
  99.      same way, but the breakpoint is automatically disabled the
  100.      first time it is hit.  *Note Disabling::.
  101.  
  102. `rbreak REGEX'
  103.      Set breakpoints on all functions matching the regular expression
  104.      REGEX.  This is useful for setting breakpoints on overloaded
  105.      functions that are not members of any special classes.  This
  106.      command sets an unconditional breakpoint on all matches,
  107.      printing a list of all breakpoints it set. Once these
  108.      breakpoints are set, they are treated just like the breakpoints
  109.      set with the `break' command.  They can be deleted, disabled,
  110.      made conditional, etc., in the standard ways.
  111.  
  112. `info breakpoints [N]'
  113. `info break [N]'
  114.      Print a list of all breakpoints (but not watchpoints) set and
  115.      not deleted, showing their numbers, where in the program they
  116.      are, and any special features in use for them. Disabled
  117.      breakpoints are included in the list, but marked as disabled.
  118.      `info break' with a breakpoint number N as argument lists only
  119.      that breakpoint.  The convenience variable `$_' and the default
  120.      examining-address for the `x' command are set to the address of
  121.      the last breakpoint listed (*note Memory::.).  The equivalent
  122.      command for watchpoints is `info watch'.
  123.  
  124.    GDB allows you to set any number of breakpoints at the same place
  125. in the program.  There is nothing silly or meaningless about this. 
  126. When the breakpoints are conditional, this is even useful (*note
  127. Conditions::.).
  128.  
  129. 
  130. File: gdb.info,  Node: Set Watchpoints,  Next: Exception Handling,  Prev: Set Breaks,  Up: Breakpoints
  131.  
  132. Setting Watchpoints
  133. -------------------
  134.  
  135.    You can use a watchpoint to stop execution whenever the value of
  136. an expression changes, without having to predict a particular place 
  137. where this may happen.
  138.  
  139.    Watchpoints currently execute two orders of magnitude more slowly
  140. than other breakpoints, but this can well be worth it to catch
  141. errors where you have no clue what part of your program is the
  142. culprit.  Some processors provide special hardware to support
  143. watchpoint evaluation; future releases of GDB will use such hardware
  144. if it is available.
  145.  
  146. `watch EXPR'
  147.      Set a watchpoint for an expression.
  148.  
  149. `info watchpoints'
  150.      This command prints a list of watchpoints; it is otherwise
  151.      similar to `info break'.
  152.  
  153. 
  154. File: gdb.info,  Node: Exception Handling,  Next: Delete Breaks,  Prev: Set Watchpoints,  Up: Breakpoints
  155.  
  156. Breakpoints and Exceptions
  157. --------------------------
  158.  
  159.    Some languages, such as GNU C++, implement exception handling. 
  160. GDB can be used to examine what caused the program to raise an
  161. exception and to list the exceptions the program is prepared to
  162. handle at a given point in time.
  163.  
  164. `catch EXCEPTIONS'
  165.      You can set breakpoints at active exception handlers by using
  166.      the `catch' command.  EXCEPTIONS is a list of names of
  167.      exceptions to catch.
  168.  
  169.    You can use `info catch' to list active exception handlers; *note
  170. Frame Info::..
  171.  
  172.    There are currently some limitations to exception handling in GDB.
  173. These will be corrected in a future release.
  174.  
  175.    * If you call a function interactively, GDB normally returns
  176.      control to you when the function has finished executing.  If
  177.      the call raises an exception, however, the call may bypass the
  178.      mechanism that returns control to the user and cause the
  179.      program to simply continue running until it hits a breakpoint,
  180.      catches a signal that GDB is listening for, or exits.
  181.  
  182.    * You cannot raise an exception interactively.
  183.  
  184.    * You cannot interactively install an exception handler.
  185.  
  186.    Sometimes `catch' is not the best way to debug exception handling:
  187. if you need to know exactly where an exception is raised, it's
  188. better to stop *before* the exception handler is called, since that
  189. way you can see the stack before any unwinding takes place.  If you
  190. set a breakpoint in an exception handler instead, it may not be easy
  191. to find out where the exception was raised.
  192.  
  193.    To stop just before an exception handler is called, you need some
  194. knowledge of the implementation.  In the case of GNU C++ exceptions
  195. are raised by calling a library function named `__raise_exception'
  196. which has the following ANSI C interface:
  197.  
  198.          /* ADDR is where the exception identifier is stored.
  199.             ID is the exception identifier.  */
  200.          void __raise_exception (void **ADDR, void *ID);
  201.  
  202. To make the debugger catch all exceptions before any stack unwinding
  203. takes place, set a breakpoint on `__raise_exception' (*note
  204. Breakpoints::.).
  205.  
  206.    With a conditional breakpoint (*Note Conditions::) that depends on
  207. the value of ID, you can stop your program when a specific exception
  208. is raised.  You can use multiple conditional breakpoints to stop the
  209. program when any of a number of exceptions are raised.
  210.  
  211. 
  212. File: gdb.info,  Node: Delete Breaks,  Next: Disabling,  Prev: Exception Handling,  Up: Breakpoints
  213.  
  214. Deleting Breakpoints
  215. --------------------
  216.  
  217.    It is often necessary to eliminate a breakpoint or watchpoint once
  218. it has done its job and you no longer want the program to stop
  219. there.  This is called "deleting" the breakpoint.  A breakpoint that
  220. has been deleted no longer exists; it is forgotten.
  221.  
  222.    With the `clear' command you can delete breakpoints according to
  223. where they are in the program.  With the `delete' command you can
  224. delete individual breakpoints or watchpoints by specifying their
  225. breakpoint numbers.
  226.  
  227.    It is not necessary to delete a breakpoint to proceed past it. 
  228. GDB automatically ignores breakpoints on the first instruction to be
  229. executed when you continue execution without changing the execution
  230. address.
  231.  
  232. `clear'
  233.      Delete any breakpoints at the next instruction to be executed in
  234.      the selected stack frame (*note Selection::.).  When the
  235.      innermost frame is selected, this is a good way to delete a
  236.      breakpoint that the program just stopped at.
  237.  
  238. `clear FUNCTION'
  239. `clear FILENAME:FUNCTION'
  240.      Delete any breakpoints set at entry to the function FUNCTION.
  241.  
  242. `clear LINENUM'
  243. `clear FILENAME:LINENUM'
  244.      Delete any breakpoints set at or within the code of the
  245.      specified line.
  246.  
  247. `delete [breakpoints] [BNUMS...]'
  248.      Delete the breakpoints or watchpoints of the numbers specified
  249.      as arguments.  If no argument is specified, delete all
  250.      breakpoints (GDB asks confirmation, unless you've `set confirm
  251.      off').  You can abbreviate this command as `d'.
  252.  
  253. 
  254. File: gdb.info,  Node: Disabling,  Next: Conditions,  Prev: Delete Breaks,  Up: Breakpoints
  255.  
  256. Disabling Breakpoints
  257. ---------------------
  258.  
  259.    Rather than deleting a breakpoint or watchpoint, you might prefer
  260. to "disable" it.  This makes the breakpoint inoperative as if it had
  261. been deleted, but remembers the information on the breakpoint so
  262. that you can "enable" it again later.
  263.  
  264.    You disable and enable breakpoints and watchpoints with the
  265. `enable' and `disable' commands, optionally specifying one or more
  266. breakpoint numbers as arguments.  Use `info break' or `info watch'
  267. to print a list of breakpoints or watchpoints if you don't know
  268. which numbers to use.
  269.  
  270.    A breakpoint or watchpoint can have any of four different states
  271. of enablement:
  272.  
  273.    * Enabled.  The breakpoint will stop the program.  A breakpoint
  274.      set with the `break' command starts out in this state.
  275.  
  276.    * Disabled.  The breakpoint has no effect on the program.
  277.  
  278.    * Enabled once.  The breakpoint will stop the program, but when it
  279.      does so it will become disabled.  A breakpoint set with the
  280.      `tbreak' command starts out in this state.
  281.  
  282.    * Enabled for deletion.  The breakpoint will stop the program, but
  283.      immediately after it does so it will be deleted permanently.
  284.  
  285.    You can use the following commands to enable or disable
  286. breakpoints and watchpoints:
  287.  
  288. `disable [breakpoints] [BNUMS...]'
  289.      Disable the specified breakpoints--or all breakpoints, if none
  290.      are listed.  A disabled breakpoint has no effect but is not
  291.      forgotten.  All options such as ignore-counts, conditions and
  292.      commands are remembered in case the breakpoint is enabled again
  293.      later.  You may abbreviate `disable' as `dis'.
  294.  
  295. `enable [breakpoints] [BNUMS...]'
  296.      Enable the specified breakpoints (or all defined breakpoints). 
  297.      They become effective once again in stopping the program.
  298.  
  299. `enable [breakpoints] once BNUMS...'
  300.      Enable the specified breakpoints temporarily.  Each will be
  301.      disabled again the next time it stops the program.
  302.  
  303. `enable [breakpoints] delete BNUMS...'
  304.      Enable the specified breakpoints to work once and then die. 
  305.      Each of the breakpoints will be deleted the next time it stops
  306.      the program.
  307.  
  308.    Save for a breakpoint set with `tbreak' (*note Set Breaks::.),
  309. breakpoints that you set are initially enabled; subsequently, they
  310. become disabled or enabled only when you use one of the commands
  311. above.  (The command `until' can set and delete a breakpoint of its
  312. own,
  313. but it will not change the state of your other breakpoints; *note
  314. Continuing and Stepping::..)
  315.  
  316. 
  317. File: gdb.info,  Node: Conditions,  Next: Break Commands,  Prev: Disabling,  Up: Breakpoints
  318.  
  319. Break Conditions
  320. ----------------
  321.  
  322.    The simplest sort of breakpoint breaks every time the program
  323. reaches a specified place.  You can also specify a "condition" for a
  324. breakpoint.  A condition is just a Boolean expression in your
  325. programming language.  (*Note Expressions::).  A breakpoint with a
  326. condition evaluates the expression each time the program reaches it,
  327. and the program stops only if the condition is *true*.
  328.  
  329.    This is the converse of using assertions for program validation;
  330. in that situation, you want to stop when the assertion is
  331. violated--that is, when the condition is false.  In C, if you want
  332. to test an assertion expressed by the condition ASSERT, you should
  333. set the condition  `! ASSERT' on the appropriate breakpoint.
  334.  
  335.    Conditions are also accepted for watchpoints; you may not need
  336. them, since a watchpoint is inspecting the value of an expression
  337. anyhow--but it might be simpler, say, to just set a watchpoint on a
  338. variable name, and specify a condition that tests whether the new
  339. value is an interesting one.
  340.  
  341.    Break conditions ca have side effects, and may even call functions
  342. in your program.  This can be useful, for example, to activate
  343. functions that log program progress, or to use your own print
  344. functions to format special data structures. The effects are
  345. completely
  346. predictable unless there is another enabled breakpoint at the same
  347. address.  (In that case, GDB might see the other breakpoint first
  348. and stop the program without checking the condition of this one.) 
  349. Note that breakpoint commands are usually more convenient and
  350. flexible for the purpose of performing side effects when a
  351. breakpoint is reached (*note Break Commands::.).
  352.  
  353.    Break conditions can be specified when a breakpoint is set, by
  354. using `if' in the arguments to the `break' command.  *Note Set
  355. Breaks::.  They can also be changed at any time with the `condition'
  356. command.  The `watch' command doesn't recognize the `if' keyword;
  357. `condition' is the only way to impose a further condition on a
  358. watchpoint.
  359.  
  360. `condition BNUM EXPRESSION'
  361.      Specify EXPRESSION as the break condition for breakpoint or
  362.      watchpoint number BNUM.  From now on, this breakpoint will stop
  363.      the program only if the value of EXPRESSION is true (nonzero,
  364.      in C).  When you use `condition', GDB checks EXPRESSION
  365.      immediately for syntactic correctness, and to determine whether
  366.      symbols in it have referents in the context of your breakpoint.
  367.      GDB does not actually evaluate EXPRESSION at the time the
  368.      `condition' command is given, however.  *Note Expressions::.
  369.  
  370. `condition BNUM'
  371.      Remove the condition from breakpoint number BNUM.  It becomes an
  372.      ordinary unconditional breakpoint.
  373.  
  374.    A special case of a breakpoint condition is to stop only when the
  375. breakpoint has been reached a certain number of times.  This is so
  376. useful that there is a special way to do it, using the "ignore
  377. count" of the breakpoint.  Every breakpoint has an ignore count,
  378. which is an integer.  Most of the time, the ignore count is zero,
  379. and therefore has no effect.  But if the program reaches a
  380. breakpoint whose ignore count is positive, then instead of stopping,
  381. it just decrements the ignore count by one and continues.  As a
  382. result,
  383. if the ignore count value is N, the breakpoint will not stop the
  384. next N times it is reached.
  385.  
  386. `ignore BNUM COUNT'
  387.      Set the ignore count of breakpoint number BNUM to COUNT.  The
  388.      next COUNT times the breakpoint is reached, your program's
  389.      execution will not stop; other than to decrement the ignore
  390.      count, GDB takes no action.
  391.  
  392.      To make the breakpoint stop the next time it is reached, specify
  393.      a count of zero.
  394.  
  395. `continue COUNT'
  396. `c COUNT'
  397. `fg COUNT'
  398.      Continue execution of the program, setting the ignore count of
  399.      the breakpoint that the program stopped at to COUNT minus one. 
  400.      Thus, the program will not stop at this breakpoint until the
  401.      COUNT'th time it is reached.
  402.  
  403.      An argument to this command is meaningful only when the program
  404.      stopped due to a breakpoint.  At other times, the argument to
  405.      `continue' is ignored.
  406.  
  407.      The synonym `fg' is provided purely for convenience, and has
  408.      exactly the same behavior as other forms of the command.
  409.  
  410.    If a breakpoint has a positive ignore count and a condition, the
  411. condition is not checked.  Once the ignore count reaches zero, the
  412. condition will be checked.
  413.  
  414.    You could achieve the effect of the ignore count with a condition
  415. such as `$foo-- <= 0' using a debugger convenience variable that is
  416. decremented each time.  *Note Convenience Vars::.
  417.  
  418. 
  419. File: gdb.info,  Node: Break Commands,  Next: Breakpoint Menus,  Prev: Conditions,  Up: Breakpoints
  420.  
  421. Breakpoint Command Lists
  422. ------------------------
  423.  
  424.    You can give any breakpoint (or watchpoint) a series of commands
  425. to execute when the program stops due to that breakpoint.  For
  426. example, you might want to print the values of certain expressions,
  427. or enable other breakpoints.
  428.  
  429. `commands [BNUM]'
  430. `... COMMAND-LIST ...'
  431. `end'
  432.      Specify a list of commands for breakpoint number BNUM.  The
  433.      commands themselves appear on the following lines.  Type a line
  434.      containing just `end' to terminate the commands.
  435.  
  436.      To remove all commands from a breakpoint, type `commands'
  437.      followed immediately by `end'; that is, give no commands.
  438.  
  439.      With no BNUM argument, `commands' refers to the last breakpoint
  440.      or watchpoint set (not to the breakpoint most recently
  441.      encountered).
  442.  
  443.    Pressing RET as a means of repeating the last GDB command is
  444. disabled within a COMMAND-LIST.
  445.  
  446.    You can use breakpoint commands to start the program up again. 
  447. Simply use the `continue' command, or `step', or any other command
  448. that resumes execution.  Subsequent commands in the command list are
  449. ignored.
  450.  
  451.    If the first command specified is `silent', the usual message
  452. about stopping at a breakpoint is not printed.  This may be
  453. desirable for breakpoints that are to print a specific message and
  454. then continue.  If the remaining commands too print nothing, you
  455. will see no sign that the breakpoint was reached at all.  `silent'
  456. is meaningful only  at the beginning of a breakpoint command list.
  457.  
  458.    The commands `echo' and `output' that allow you to print precisely
  459. controlled output are often useful in silent breakpoints.  *Note
  460. Output::.
  461.  
  462.    For example, here is how you could use breakpoint commands to
  463. print the value of `x' at entry to `foo' whenever `x' is positive.
  464.  
  465.      break foo if x>0
  466.      commands
  467.      silent
  468.      echo x is\040
  469.      output x
  470.      echo \n
  471.      cont
  472.      end
  473.  
  474.    One application for breakpoint commands is to compensate for one
  475. bug so you can test for another.  Put a breakpoint just after the
  476. erroneous line of code, give it a condition to detect the case in
  477. which something erroneous has been done, and give it commands to
  478. assign correct values to any variables that need them.  End with the
  479. `continue' command so that the program does not stop, and start with
  480. the `silent' command so that no output is produced.  Here is an
  481. example:
  482.  
  483.      break 403
  484.      commands
  485.      silent
  486.      set x = y + 4
  487.      cont
  488.      end
  489.  
  490.    One deficiency in the operation of automatically continuing
  491. breakpoints under Unix appears when your program uses raw mode for
  492. the
  493. terminal.  GDB switches back to its own terminal modes (not raw)
  494. before executing commands, and then must switch back to raw mode
  495. when your program is continued.  This causes any pending terminal
  496. input to be lost.
  497.  
  498.    Under Unix, you can get around this problem by writing actions
  499. into the breakpoint condition rather than in commands.  For example
  500.  
  501.      condition 5  (x = y + 4), 0
  502.  
  503. specifies a condition expression (*Note Expressions::) that will
  504. change `x' as needed, then always have the value zero so the program
  505. will not stop.  No input is lost here, because GDB evaluates break
  506. conditions  without changing the terminal modes.  When you want to
  507. have nontrivial conditions for performing the side effects, the
  508. operators `&&', `||' and `?...:' may be useful.
  509.  
  510. 
  511. File: gdb.info,  Node: Breakpoint Menus,  Next: Error in Breakpoints,  Prev: Break Commands,  Up: Breakpoints
  512.  
  513. Breakpoint Menus
  514. ----------------
  515.  
  516.    Some programming languages (notably C++) permit a single function
  517. name to be defined several times, for application in different
  518. contexts.  This is called "overloading".  When a function name is
  519. overloaded, `break FUNCTION' is not enough to tell GDB where you
  520. want a breakpoint.  GDB offers you a menu of numbered choices for
  521. different possible breakpoints, and waits for your selection with
  522. the prompt `>'.  The first two options are always `[0] cancel' and
  523. `[1] all'.  Typing `1' sets a breakpoint at each definition of
  524. FUNCTION, and typing `0' aborts the `break' command without setting
  525. any new breakpoints.
  526.  
  527.    For example, the following session excerpt shows an attempt to set
  528. a breakpoint at the overloaded symbol `String::after'.   We choose
  529. three particular definitions of that function name:
  530.  
  531.      (gdb) b String::after
  532.      [0] cancel
  533.      [1] all
  534.      [2] file:String.cc; line number:867
  535.      [3] file:String.cc; line number:860
  536.      [4] file:String.cc; line number:875
  537.      [5] file:String.cc; line number:853
  538.      [6] file:String.cc; line number:846
  539.      [7] file:String.cc; line number:735
  540.      > 2 4 6
  541.      Breakpoint 1 at 0xb26c: file String.cc, line 867.
  542.      Breakpoint 2 at 0xb344: file String.cc, line 875.
  543.      Breakpoint 3 at 0xafcc: file String.cc, line 846.
  544.      Multiple breakpoints were set.
  545.      Use the "delete" command to delete unwanted breakpoints.
  546.      (gdb)
  547.  
  548. 
  549. File: gdb.info,  Node: Error in Breakpoints,  Prev: Breakpoint Menus,  Up: Breakpoints
  550.  
  551. "Cannot Insert Breakpoints"
  552. ---------------------------
  553.  
  554.    Under some operating systems, breakpoints cannot be used in a
  555. program if any other process is running that program.  In this
  556. situation, attempting to run or continue a program with a breakpoint
  557. causes GDB to stop the other process.
  558.  
  559.    When this happens, you have three ways to proceed:
  560.  
  561.   1. Remove or disable the breakpoints, then continue.
  562.  
  563.   2. Suspend GDB, and copy the file containing the program to a new
  564.      name.  Resume GDB and use the `exec-file' command to specify
  565.      that GDB should run the program under that name.  Then start
  566.      the program again.
  567.  
  568.   3. Relink the program so that the text segment is nonsharable,
  569.      using the linker option `-N'.  The operating system limitation
  570.      may not apply to nonsharable executables.
  571.  
  572. 
  573. File: gdb.info,  Node: Continuing and Stepping,  Next: Signals,  Prev: Breakpoints,  Up: Stopping
  574.  
  575. Continuing and Stepping
  576. =======================
  577.  
  578.    "Continuing" means resuming program execution until your program
  579. completes normally.  In contrast, "stepping" means resuming program
  580. execution for a very limited time: one line of source code, or one
  581. machine instruction.  Either when continuing or when stepping, the
  582. program may stop even sooner, due to a breakpoint or to a signal. 
  583. (If due to a signal, you may want to use `handle', or use `signal 0'
  584. to resume execution; *note Signals::..)
  585.  
  586. `continue [IGNORE-COUNT]'
  587.      Resume program execution, at the address where the program last
  588.      stopped; any breakpoints set at that address are bypassed.  The
  589.      optional argument IGNORE-COUNT allows you to specify a further
  590.      number of times to ignore a breakpoint at this location; its
  591.      effect is like that of `ignore' (*note Conditions::.).
  592.  
  593.      To resume execution at a different place, you can use `return'
  594.      (*note Returning::.) to go back to the calling function; or
  595.      `jump' (*note Jumping::.) to go to an arbitrary location in
  596.      your program.
  597.  
  598.    A typical technique for using stepping is to set a breakpoint
  599. (*note Breakpoints::.) at the beginning of the function or the
  600. section of the program in which a problem is believed to lie, run
  601. the program until it stops at that breakpoint, and then step through
  602. the suspect area, examining the variables that are interesting,
  603. until you see the problem happen.
  604.  
  605. `step'
  606.      Continue running the program until control reaches a different
  607.      source line, then stop it and return control to GDB.  This
  608.      command is abbreviated `s'.
  609.  
  610.           *Warning:* If you use the `step' command while control is
  611.           within a function that was compiled without debugging
  612.           information, execution will proceed until control reaches
  613.           another function.
  614.  
  615. `step COUNT'
  616.      Continue running as in `step', but do so COUNT times.  If a
  617.      breakpoint is reached or a signal not related to stepping
  618.      occurs before COUNT steps, stepping stops right away.
  619.  
  620. `next [COUNT]'
  621.      Continue to the next source line in the current (innermost)
  622.      stack frame.  Similar to `step', but any function calls
  623.      appearing within the line of code are executed without
  624.      stopping.  Execution stops when control reaches a different
  625.      line of code at the stack level which was executing when the
  626.     
  627.      `next' command was given.  This command is abbreviated `n'.
  628.  
  629.      An argument COUNT is a repeat count, as for `step'.
  630.  
  631.      `next' within a function that lacks debugging information acts
  632.      like `step', but any function calls appearing within the code
  633.      of the function are executed without stopping.
  634.  
  635. `finish'
  636.      Continue running until just after function in the selected stack
  637.      frame returns.  Print the returned value (if any).
  638.  
  639.      Contrast this with the `return' command (*note Returning::.).
  640.  
  641. `until'
  642. `u'
  643.      Continue running until a source line past the current line, in
  644.      the current stack frame, is reached.  This command is used to
  645.      avoid single stepping through a loop more than once.  It is
  646.      like the `next' command, except that when `until' encounters a
  647.      jump, it automatically continues execution until the program
  648.      counter is greater than the address of the jump.
  649.  
  650.      This means that when you reach the end of a loop after single
  651.      stepping though it, `until' will cause the program to continue
  652.      execution until the loop is exited.  In contrast, a `next'
  653.      command at the end of a loop will simply step back to the
  654.      beginning of the loop, which would force you to step through
  655.      the next iteration.
  656.  
  657.      `until' always stops the program if it attempts to exit the
  658.      current stack frame.
  659.  
  660.      `until' may produce somewhat counterintuitive results if the
  661.      order of machine code does not match the order of the source
  662.      lines.  For example, in the following excerpt from a debugging
  663.      session, the `f' (`frame') command shows that execution is
  664.      stopped at line `206'; yet when we use `until', we get to line
  665.      `195':
  666.  
  667.           (gdb) f
  668.           #0  main (argc=4, argv=0xf7fffae8) at m4.c:206
  669.           206            expand_input();
  670.           (gdb) until
  671.           195        for ( ; argc > 0; NEXTARG) {
  672.  
  673.      This happened because, for execution efficiency, the compiler
  674.      had generated code for the loop closure test at the end, rather
  675.      than the start, of the loop--even though the test in a C
  676.      `for'-loop is written before the body of the loop.  The `until'
  677.      command appeared to step back to the beginning of the loop when
  678.      it advanced to this expression; however, it has not really gone
  679.      to an earlier statement--not in terms of the actual machine code.
  680.  
  681.      `until' with no argument works by means of single instruction
  682.      stepping, and hence is slower than `until' with an argument.
  683.  
  684. `until LOCATION'
  685. `u LOCATION'
  686.      Continue running the program until either the specified location
  687.      is reached, or the current stack frame returns.  LOCATION is
  688.      any of the forms of argument acceptable to `break' (*note Set
  689.      Breaks::.).  This form of the command uses breakpoints, and
  690.      hence is quicker than `until' without an argument.
  691.  
  692. `stepi'
  693. `si'
  694.      Execute one machine instruction, then stop and return to the
  695.      debugger.
  696.  
  697.      It is often useful to do `display/i $pc' when stepping by
  698.      machine instructions.  This will cause the next instruction to
  699.      be executed to be displayed automatically at each stop.  *Note
  700.      Auto Display::.
  701.  
  702.      An argument is a repeat count, as in `step'.
  703.  
  704. `nexti'
  705. `ni'
  706.      Execute one machine instruction, but if it is a function call,
  707.      proceed until the function returns.
  708.  
  709.      An argument is a repeat count, as in `next'.
  710.  
  711. 
  712. File: gdb.info,  Node: Signals,  Prev: Continuing and Stepping,  Up: Stopping
  713.  
  714. Signals
  715. =======
  716.  
  717.    A signal is an asynchronous event that can happen in a program. 
  718. The operating system defines the possible kinds of signals, and
  719. gives each kind a name and a number.  For example, in Unix `SIGINT'
  720. is the signal a program gets when you type an interrupt (often
  721. `C-c'); `SIGSEGV' is the signal a program gets from referencing a
  722. place in memory far away from all the areas in use; `SIGALRM' occurs
  723. when the alarm clock timer goes off (which happens only if the
  724. program has requested an alarm).
  725.  
  726.    Some signals, including `SIGALRM', are a normal part of the
  727. functioning of the program.  Others, such as `SIGSEGV', indicate
  728. errors; these signals are "fatal" (kill the program immediately) if
  729. the program has not specified in advance some other way to handle
  730. the signal.  `SIGINT' does not indicate an error in the program, but
  731. it is normally fatal so it can carry out the purpose of the
  732. interrupt: to kill the program.
  733.  
  734.    GDB has the ability to detect any occurrence of a signal in the
  735. program running under GDB's control.  You can tell GDB in advance
  736. what to do for each kind of signal.
  737.  
  738.    Normally, GDB is set up to ignore non-erroneous signals like
  739. `SIGALRM' (so as not to interfere with their role in the functioning
  740. of the program) but to stop the program immediately whenever an
  741. error signal happens.  You can change these settings with the
  742. `handle' command.
  743.  
  744. `info signals'
  745.      Print a table of all the kinds of signals and how GDB has been
  746.      told to handle each one.  You can use this to see the signal
  747.      numbers of all the defined types of signals.
  748.  
  749. `handle SIGNAL KEYWORDS...'
  750.      Change the way GDB handles signal SIGNAL.  SIGNAL can be the
  751.      number of a signal or its name (with or without the `SIG' at
  752.      the beginning).  The KEYWORDS say what change to make.
  753.  
  754.    The keywords allowed by the `handle' command can be abbreviated. 
  755. Their full names are:
  756.  
  757. `nostop'
  758.      GDB should not stop the program when this signal happens.  It
  759.      may still print a message telling you that the signal has come
  760.      in.
  761.  
  762. `stop'
  763.      GDB should stop the program when this signal happens.  This
  764.      implies the `print' keyword as well.
  765.  
  766. `print'
  767.      GDB should print a message when this signal happens.
  768.  
  769. `noprint'
  770.      GDB should not mention the occurrence of the signal at all. 
  771.      This implies the `nostop' keyword as well.
  772.  
  773. `pass'
  774.      GDB should allow the program to see this signal; the program
  775.      will be able to handle the signal, or may be terminated if the
  776.      signal is fatal and not handled.
  777.  
  778. `nopass'
  779.      GDB should not allow the program to see this signal.
  780.  
  781.    When a signal has been set to stop the program, the program cannot
  782. see the signal until you continue.  It will see the signal then, if
  783. `pass' is in effect for the signal in question at that time.  In
  784. other words, after GDB reports a signal, you can use the `handle'
  785. command with `pass' or `nopass' to control whether that signal will
  786. be seen by the program when you later continue it.
  787.  
  788.    You can also use the `signal' command to prevent the program from
  789. seeing a signal, or cause it to see a signal it normally would not
  790. see, or to give it any signal at any time.  For example, if the
  791. program stopped due to some sort of memory reference error, you
  792. might store correct values into the erroneous variables and
  793. continue, hoping to see more execution; but the program would
  794. probably terminate immediately as a result of the fatal signal once
  795. it sees the signal.  To prevent this, you can continue with `signal
  796. 0'.  *Note Signaling::.
  797.  
  798. 
  799. File: gdb.info,  Node: Stack,  Next: Source,  Prev: Stopping,  Up: Top
  800.  
  801. Examining the Stack
  802. *******************
  803.  
  804.    When your program has stopped, the first thing you need to know is
  805. where it stopped and how it got there.
  806.  
  807.    Each time your program performs a function call, the information
  808. about where in the program the call was made from is saved in a
  809. block of data called a "stack frame".  The frame also contains the
  810. arguments of the call and the local variables of the function that
  811. was called.  All the stack frames are allocated in a region of
  812. memory called the "call stack".
  813.  
  814.    When your program stops, the GDB commands for examining the stack
  815. allow you to see all of this information.
  816.  
  817.    One of the stack frames is "selected" by GDB and many GDB commands
  818. refer implicitly to the selected frame.  In particular, whenever you
  819. ask GDB for the value of a variable in the program, the value is
  820. found in the selected frame.  There are special GDB commands to
  821. select whichever frame you are interested in.
  822.  
  823.    When the program stops, GDB automatically selects the currently
  824. executing frame and describes it briefly as the `frame' command does
  825. (*note Info: Frame Info.).
  826.  
  827. * Menu:
  828.  
  829. * Frames::            Stack Frames
  830. * Backtrace::            Backtraces
  831. * Selection::            Selecting a Frame
  832. * Frame Info::            Information on a Frame
  833.  
  834. 
  835. File: gdb.info,  Node: Frames,  Next: Backtrace,  Prev: Stack,  Up: Stack
  836.  
  837. Stack Frames
  838. ============
  839.  
  840.    The call stack is divided up into contiguous pieces called "stack
  841. frames", or "frames" for short; each frame is the data associated
  842. with one call to one function.  The frame contains the arguments
  843. given to the function, the function's local variables, and the
  844. address at which the function is executing.
  845.  
  846.    When your program is started, the stack has only one frame, that
  847. of the function `main'.  This is called the "initial" frame or the
  848. "outermost" frame.  Each time a function is called, a new frame is
  849. made.  Each time a function returns, the frame for that function
  850. invocation is eliminated.  If a function is recursive, there can be
  851. many frames for the same function.  The frame for the function in
  852. which execution is actually occurring is called the "innermost"
  853. frame.  This is the most recently created of all the stack frames
  854. that still exist.
  855.  
  856.    Inside your program, stack frames are identified by their
  857. addresses.  A stack frame consists of many bytes, each of which has
  858. its own address; each kind of computer has a convention for choosing
  859. one of those bytes whose address serves as the address of the frame.
  860. Usually this address is kept in a register called the "frame pointer
  861. register" while execution is going on in that frame.
  862.  
  863.    GDB assigns numbers to all existing stack frames, starting with
  864. zero for the innermost frame, one for the frame that called it, and
  865. so on upward.  These numbers do not really exist in your program;
  866. they are assigned by GDB to give you a way of designating stack
  867. frames in GDB commands.
  868.  
  869.    Some compilers allow functions to be compiled so that they operate
  870. without stack frames.  (For example, the `gcc' option
  871. `-fomit-frame-pointer' will generate functions without a frame.)
  872. This is occasionally done with heavily used library functions to
  873. save the frame setup time.  GDB has limited facilities for dealing
  874. with these function invocations.  If the innermost function
  875. invocation has no stack frame, GDB will nevertheless regard it as
  876. though it had a separate frame, which is numbered zero as usual,
  877. allowing correct tracing of the function call chain.  However, GDB
  878. has no provision for frameless functions elsewhere in the stack.
  879.  
  880. 
  881. File: gdb.info,  Node: Backtrace,  Next: Selection,  Prev: Frames,  Up: Stack
  882.  
  883. Backtraces
  884. ==========
  885.  
  886.    A backtrace is a summary of how the program got where it is.  It
  887. shows one line per frame, for many frames, starting with the
  888. currently executing frame (frame zero), followed by its caller
  889. (frame one), and on up the stack.
  890.  
  891. `backtrace'
  892. `bt'
  893.      Print a backtrace of the entire stack: one line per frame for
  894.      all frames in the stack.
  895.  
  896.      You can stop the backtrace at any time by typing the system
  897.      interrupt character, normally `C-c'.
  898.  
  899. `backtrace N'
  900. `bt N'
  901.      Similar, but print only the innermost N frames.
  902.  
  903. `backtrace -N'
  904. `bt -N'
  905.      Similar, but print only the outermost N frames.
  906.  
  907.    The names `where' and `info stack' (abbreviated `info s') are
  908. additional aliases for `backtrace'.
  909.  
  910.    Each line in the backtrace shows the frame number and the function
  911. name.  The program counter value is also shown--unless you use `set
  912. print address off'.  The backtrace also shows the source file name
  913. and line number, as well as the arguments to the function.  The
  914. program counter value is omitted if it is at the beginning of the
  915. code for that line number.
  916.  
  917.    Here is an example of a backtrace.  It was made with the command
  918. `bt 3', so it shows the innermost three frames.
  919.  
  920.      #0  m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8) at builtin.c:993
  921.      #1  0x6e38 in expand_macro (sym=0x2b600) at macro.c:242
  922.      #2  0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
  923.          at macro.c:71
  924.      (More stack frames follow...)
  925.  
  926. The display for frame zero doesn't begin with a program counter
  927. value, indicating that the program has stopped at the beginning of
  928. the code for line `993' of `builtin.c'.
  929.  
  930. 
  931. File: gdb.info,  Node: Selection,  Next: Frame Info,  Prev: Backtrace,  Up: Stack
  932.  
  933. Selecting a Frame
  934. =================
  935.  
  936.    Most commands for examining the stack and other data in the
  937. program work on whichever stack frame is selected at the moment. 
  938. Here are the commands for selecting a stack frame; all of them
  939. finish by printing a brief description of the stack frame just
  940. selected.
  941.  
  942. `frame N'
  943. `f N'
  944.      Select frame number N.  Recall that frame zero is the innermost
  945.      (currently executing) frame, frame one is the frame that called
  946.      the innermost one, and so on.  The highest-numbered frame is
  947.      `main''s frame.
  948.  
  949. `frame ADDR'
  950. `f ADDR'
  951.      Select the frame at address ADDR.  This is useful mainly if the
  952.      chaining of stack frames has been damaged by a bug, making it
  953.      impossible for GDB to assign numbers properly to all frames. 
  954.      In addition, this can be useful when the program has multiple
  955.      stacks and switches between them.
  956.  
  957.      _if_(1) On the SPARC architecture, `frame' needs two addresses
  958.      to select an arbitrary frame: a frame pointer and a stack
  959.      pointer.   _fi_(1)
  960.  
  961. `up N'
  962.      Move N frames up the stack.  For positive numbers N, this
  963.      advances toward the outermost frame, to higher frame numbers,
  964.      to frames that have existed longer.  N defaults to one.
  965.  
  966. `down N'
  967.      Move N frames down the stack.  For positive numbers N, this
  968.      advances toward the innermost frame, to lower frame numbers, to
  969.      frames that were created more recently.  N defaults to one. 
  970.      You may abbreviate `down' as `do'.
  971.  
  972.    All of these commands end by printing two lines of output
  973. describing the frame.  The first line shows the frame number, the
  974. function name, the arguments, and the source file and line number of
  975. execution in that frame.  The second line shows the text of that
  976. source line.  For example:
  977.  
  978.      (gdb) up
  979.      #1  0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc) at env.c:10
  980.      10              read_input_file (argv[i]);
  981.  
  982.    After such a printout, the `list' command with no arguments will
  983. print ten lines centered on the point of execution in the frame. 
  984. *Note List::.
  985.  
  986. `up-silently N'
  987. `down-silently N'
  988.      These two commands are variants of `up' and `down',
  989.      respectively; they differ in that they do their work silently,
  990.      without causing display of the new frame.  They are intended
  991.      primarily for use in GDB command scripts, where the output
  992.      might be unnecessary and distracting.
  993.  
  994. 
  995. File: gdb.info,  Node: Frame Info,  Prev: Selection,  Up: Stack
  996.  
  997. Information About a Frame
  998. =========================
  999.  
  1000.    There are several other commands to print information about the
  1001. selected stack frame.
  1002.  
  1003. `frame'
  1004. `f'
  1005.      When used without any argument, this command does not change
  1006.      which frame is selected, but prints a brief description of the
  1007.      currently selected stack frame.  It can be abbreviated `f'. 
  1008.      With an argument, this command is used to select a stack frame
  1009.      (*note Selection::.).
  1010.  
  1011. `info frame'
  1012. `info f'
  1013.      This command prints a verbose description of the selected stack
  1014.      frame, including the address of the frame, the addresses of the
  1015.      next frame down (called by this frame) and the next frame up
  1016.      (caller of this frame), the address of the frame's arguments,
  1017.      the program counter saved in it (the address of execution in
  1018.      the caller frame), and which registers were saved in the frame.
  1019.      The verbose description is useful when something has gone wrong
  1020.      that has made the stack format fail to fit the usual conventions.
  1021.  
  1022. `info frame ADDR'
  1023. `info f ADDR'
  1024.      Print a verbose description of the frame at address ADDR,
  1025.      without selecting that frame.  The selected frame remains
  1026.      unchanged by this command.
  1027.  
  1028. `info args'
  1029.      Print the arguments of the selected frame, each on a separate
  1030.      line.
  1031.  
  1032. `info locals'
  1033.      Print the local variables of the selected frame, each on a
  1034.      separate line.  These are all variables declared static or
  1035.      automatic within all program blocks that execution in this
  1036.      frame
  1037.      is currently inside of.
  1038.  
  1039. `info catch'
  1040.      Print a list of all the exception handlers that are active in
  1041.      the current stack frame at the current point of execution.  To
  1042.      see other exception handlers, visit the associated frame (using
  1043.      the `up', `down', or `frame' commands); then type `info catch'.
  1044.      *Note Exception Handling::.
  1045.  
  1046. 
  1047. File: gdb.info,  Node: Source,  Next: Data,  Prev: Stack,  Up: Top
  1048.  
  1049. Examining Source Files
  1050. **********************
  1051.  
  1052.    GDB can print parts of your program's source, since the debugging
  1053. information recorded in your program tells GDB what source files
  1054. were used to built it.  When your program stops, GDB spontaneously
  1055. prints the line where it stopped.  Likewise, when you select a stack
  1056. frame (*note Selection::.), GDB prints the line where execution in
  1057. that frame has stopped.  You can print other portions of source
  1058. files by explicit command.
  1059.  
  1060.    If you use GDB through its GNU Emacs interface, you may prefer to
  1061. use Emacs facilities to view source; *note Emacs::..
  1062.  
  1063. * Menu:
  1064.  
  1065. * List::            Printing Source Lines
  1066. * Search::            Searching Source Files
  1067. * Source Path::            Specifying Source Directories
  1068. * Machine Code::        Source and Machine Code
  1069.  
  1070. 
  1071. File: gdb.info,  Node: List,  Next: Search,  Prev: Source,  Up: Source
  1072.  
  1073. Printing Source Lines
  1074. =====================
  1075.  
  1076.    To print lines from a source file, use the `list' command
  1077. (abbreviated `l').  There are several ways to specify what part of
  1078. the file you want to print.
  1079.  
  1080.    Here are the forms of the `list' command most commonly used:
  1081.  
  1082. `list LINENUM'
  1083.      Print ten lines centered around line number LINENUM in the
  1084.      current source file.
  1085.  
  1086. `list FUNCTION'
  1087.      Print ten lines centered around the beginning of function
  1088.      FUNCTION.
  1089.  
  1090. `list'
  1091.      Print ten more lines.  If the last lines printed were printed
  1092.      with a `list' command, this prints ten lines following the last
  1093.      lines printed; however, if the last line printed was a solitary
  1094.      line printed as part of displaying a stack frame (*note
  1095.      Stack::.), this prints ten lines centered around that line.
  1096.  
  1097. `list -'
  1098.      Print ten lines just before the lines last printed.
  1099.  
  1100.    Repeating a `list' command with RET discards the argument, so it
  1101. is equivalent to typing just `list'.  This is more useful than
  1102. listing the same lines again.  An exception is made for an argument
  1103. of `-'; that argument is preserved in repetition so that each
  1104. repetition moves up in the source file.
  1105.  
  1106.    In general, the `list' command expects you to supply zero, one or
  1107. two "linespecs".  Linespecs specify source lines; there are several
  1108. ways of writing them but the effect is always to specify some source
  1109. line.  Here is a complete description of the possible arguments for
  1110. `list':
  1111.  
  1112. `list LINESPEC'
  1113.      Print ten lines centered around the line specified by LINESPEC.
  1114.  
  1115. `list FIRST,LAST'
  1116.      Print lines from FIRST to LAST.  Both arguments are linespecs.
  1117.  
  1118. `list ,LAST'
  1119.      Print ten lines ending with LAST.
  1120.  
  1121. `list FIRST,'
  1122.      Print ten lines starting with FIRST.
  1123.  
  1124. `list +'
  1125.      Print ten lines just after the lines last printed.
  1126.  
  1127. `list -'
  1128.      Print ten lines just before the lines last printed.
  1129.  
  1130. `list'
  1131.      As described in the preceding table.
  1132.  
  1133.    Here are the ways of specifying a single source line--all the
  1134. kinds of linespec.
  1135.  
  1136. `NUMBER'
  1137.      Specifies line NUMBER of the current source file.  When a `list'
  1138.      command has two linespecs, this refers to the same source file
  1139.      as the first linespec.
  1140.  
  1141. `+OFFSET'
  1142.      Specifies the line OFFSET lines after the last line printed. 
  1143.      When used as the second linespec in a `list' command that has
  1144.      two, this specifies the line OFFSET lines down from the first
  1145.      linespec.
  1146.  
  1147. `-OFFSET'
  1148.      Specifies the line OFFSET lines before the last line printed.
  1149.  
  1150. `FILENAME:NUMBER'
  1151.      Specifies line NUMBER in the source file FILENAME.
  1152.  
  1153. `FUNCTION'
  1154.      Specifies the line of the open-brace that begins the body of the
  1155.      function FUNCTION.
  1156.  
  1157. `FILENAME:FUNCTION'
  1158.      Specifies the line of the open-brace that begins the body of the
  1159.      function FUNCTION in the file FILENAME.  You only need the file
  1160.      name with a function name to avoid ambiguity when there are
  1161.      identically named functions in different source files.
  1162.  
  1163. `*ADDRESS'
  1164.      Specifies the line containing the program address ADDRESS. 
  1165.      ADDRESS may be any expression.
  1166.  
  1167. 
  1168. File: gdb.info,  Node: Search,  Next: Source Path,  Prev: List,  Up: Source
  1169.  
  1170. Searching Source Files
  1171. ======================
  1172.  
  1173.    There are two commands for searching through the current source
  1174. file for a regular expression.
  1175.  
  1176. `forward-search REGEXP'
  1177. `search REGEXP'
  1178.      The command `forward-search REGEXP' checks each line, starting
  1179.      with the one following the last line listed, for a match for
  1180.      REGEXP.  It lists the line that is found.  You can abbreviate
  1181.      the command name as `fo'.  The synonym `search REGEXP' is also
  1182.      supported.
  1183.  
  1184. `reverse-search REGEXP'
  1185.      The command `reverse-search REGEXP' checks each line, starting
  1186.      with the one before the last line listed and going backward,
  1187.      for a match for REGEXP.  It lists the line that is found.  You
  1188.      can abbreviate this command as `rev'.
  1189.  
  1190. 
  1191. File: gdb.info,  Node: Source Path,  Next: Machine Code,  Prev: Search,  Up: Source
  1192.  
  1193. Specifying Source Directories
  1194. =============================
  1195.  
  1196.    Executable programs sometimes do not record the directories of the
  1197. source files from which they were compiled, just the names.  Even
  1198. when they do, the directories could be moved between the compilation
  1199. and your debugging session.  GDB has a list of directories to search
  1200. for source files; this is called the "source path".  Each time GDB
  1201. wants a source file, it tries all the directories in the list, in
  1202. the order they are present in the list, until it finds a file with
  1203. the desired name.  Note that the executable search path is *not*
  1204. used for this purpose.  Neither is the current working directory,
  1205. unless it happens to be in the source path.
  1206.  
  1207.    If GDB can't find a source file in the source path, and the object
  1208. program records a directory, GDB tries that directory too.  If the
  1209. source path is empty, and there is no record of the compilation
  1210. directory, GDB will, as a last resort, look in the current directory.
  1211.  
  1212.    Whenever you reset or rearrange the source path, GDB will clear
  1213. out any information it has cached about where source files are
  1214. found, where each line is in the file, etc.
  1215.  
  1216.    When you start GDB, its source path is empty.  To add other
  1217. directories, use the `directory' command.
  1218.  
  1219. `directory DIRNAME ...'
  1220.      Add directory DIRNAME to the front of the source path.  Several
  1221.      directory names may be given to this command, separated by `:'
  1222.      or whitespace.  You may specify a directory that is already in
  1223.      the source path; this moves it forward, so it will be searched
  1224.      sooner.
  1225.  
  1226.      You can use the string `$cdir' to refer to the compilation
  1227.      directory (if one is recorded), and `$cwd' to refer to the
  1228.      current working directory.  `$cwd' is not the same as `.'--the
  1229.      former tracks the current working directory as it changes
  1230.      during your GDB session, while the latter is immediately
  1231.      expanded to the current directory at the time you add an entry
  1232.      to the source path.
  1233.  
  1234. `directory'
  1235.      Reset the source path to empty again.  This requires confirmation.
  1236.  
  1237. `show directories'
  1238.      Print the source path: show which directories it contains.
  1239.  
  1240.    If your source path is cluttered with directories that are no
  1241. longer
  1242. of interest, GDB may sometimes cause confusion by finding the wrong
  1243. versions of source.  You can correct the situation as follows:
  1244.  
  1245.   1. Use `directory' with no argument to reset the source path to
  1246.      empty.
  1247.  
  1248.   2. Use `directory' with suitable arguments to reinstall the
  1249.      directories you want in the source path.  You can add all the
  1250.      directories in one command.
  1251.  
  1252.